home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / daemons / nfs / nfs-serv.2be / nfs-serv / nfs-server-2.2beta16 / rquota_dispatch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-06  |  3.3 KB  |  142 lines

  1. /*
  2.  * rquota_dispatch    This file contains the function dispatch table.
  3.  *
  4.  * Authors:    Donald J. Becker, <becker@super.org>
  5.  *        Rick Sladkey, <jrs@world.std.com>
  6.  *        Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  7.  *        Olaf Kirch, <okir@monad.swb.de>
  8.  *
  9.  *        This software may be used for any purpose provided
  10.  *        the above copyright notice is retained.  It is supplied
  11.  *        as is, with no warranty expressed or implied.
  12.  */
  13.  
  14. #include "rquotad.h"
  15. #include "logging.h"
  16. #include "rpcmisc.h"
  17.  
  18. /*
  19.  * These are the global variables that hold all argument and result data.
  20.  */
  21. union rquotad_arguments argument;
  22. union rquotad_results    result;
  23.  
  24. /*
  25.  * This is a dispatch table to simplify error checking,
  26.  * and supply return attributes for NFS functions.
  27.  */
  28.  
  29. #ifdef __STDC__
  30. #define CONCAT(a,b)    a##b
  31. #define CONCAT3(a,b,c)    a##b##c
  32. #define STRING(a)    #a
  33. #else
  34. #define CONCAT(a,b)    a/**/b
  35. #define CONCAT3(a,b,c)    a/**/b/**/c
  36. #define STRING(a)    "a"
  37. #endif
  38.  
  39. #define table_ent(res_type, arg_type, funct) {            \
  40.     sizeof(res_type), sizeof(arg_type),            \
  41.     (xdrproc_t) CONCAT(xdr_,res_type),            \
  42.     (xdrproc_t) CONCAT(xdr_,arg_type),            \
  43.     (void *(*)()) CONCAT3(rquota_,funct,_1_svc),    \
  44.     STRING(funct), CONCAT(pr_,arg_type)            \
  45. }
  46.  
  47. #define nil    void
  48. #define xdr_nil    xdr_void
  49. #define pr_nil    pr_void
  50. #define pr_char    pr_void
  51.  
  52. struct dispatch_entry {
  53.     int        res_size, arg_size;    /* sizeof the res/arg structs    */
  54.     xdrproc_t    xdr_result;
  55.     xdrproc_t    xdr_argument;
  56.     void    *(*funct)();        /* function handler        */
  57.     char    *name;            /* name of function        */
  58.     char    *(*log_print)();    /* ptr to debug handler        */
  59. };
  60.  
  61. static _PRO(char *pr_void, (void)                    );
  62. static _PRO(char *pr_getquota_args, (getquota_args *argp)        );
  63.  
  64. static struct dispatch_entry dtable[] = {
  65.     table_ent(nil,nil,null),            /* NULL */
  66.     table_ent(getquota_rslt,getquota_args,getquota),/* GETQUOTA */
  67.     table_ent(getquota_rslt,getquota_args,getactivequota),
  68.                             /* GETACTIVEQUOTA */
  69. };
  70.  
  71.  
  72. /*
  73.  * The main dispatch routine.
  74.  */
  75. void rquota_dispatch(rqstp, transp)
  76. struct svc_req *rqstp;
  77. SVCXPRT *transp;
  78. {
  79.     unsigned int        proc_index;
  80.     struct dispatch_entry    *dent;
  81.     union rquotad_results    *resp;
  82.  
  83.     proc_index = rqstp->rq_proc;
  84.     _rpcsvcdirty = 1;
  85.  
  86.     if (proc_index >= (sizeof(dtable) / sizeof(dtable[0]))) {
  87.         svcerr_noproc(transp);
  88.         goto done;
  89.     }
  90.     dent = &dtable[proc_index];
  91.  
  92.     memset(&argument, 0, dent->arg_size);
  93.     if (!svc_getargs(transp, dent->xdr_argument, &argument)) {
  94.         svcerr_decode(transp);
  95.         goto done;
  96.     }
  97.     /* Clear the result structure. */
  98.     memset(&result, 0, dent->res_size);
  99.  
  100.     /* Log the call. */
  101.     if (logging_enabled(D_CALL))
  102.         log_call(rqstp, dent->name, dent->log_print(&argument));
  103.  
  104.     /* Do the function call itself. */
  105.     resp = (*dent->funct) (&argument, rqstp);
  106.  
  107.     if (!svc_sendreply(transp, dent->xdr_result, (caddr_t) resp)) {
  108.         svcerr_systemerr(transp);
  109.     }
  110.     if (!svc_freeargs(transp, dent->xdr_argument, &argument)) {
  111.         dprintf(L_ERROR, "unable to free RPC arguments, exiting\n");
  112.         exit(1);
  113.     }
  114.  
  115. done:
  116.     _rpcsvcdirty = 0;
  117. }
  118.  
  119. /*
  120.  * Functions for debugging output.
  121.  */
  122. static char *pr_void()
  123. {
  124.     return ("");
  125. }
  126.  
  127. static char *pr_getquota_args(argp)
  128. getquota_args *argp;
  129. {
  130.     static char    buf[1200];
  131.     char        *path = argp->gqa_pathp;
  132.  
  133.     if (strlen(path) > 1024) {
  134.         dprintf(L_WARNING, "giant pathname in getquota call: %s\n",
  135.             path);
  136.         path = "<giant path>";
  137.     }
  138.     sprintf(buf, "uid %d path %s", argp->gqa_uid, path);
  139.     return buf;
  140. }
  141.  
  142.